<?php 
/**
 * @annotate 基础类
 * @group   Admin
 * @author   mengke.yue <mengke.yue@gmail.com>
 */
class BaseAction extends Action {
	
	protected $oApp;//项目信息
	protected $oUser;//用户信息
	protected $oCom;//用户信息
	protected $aVerify = array();//需要验证的方法
	protected $aGroup = array();//需要验证的方法(身份验证 只有企业可以登录)
	protected $model;
	
	public function __construct() {
		parent::__construct();
		
		//加载项目信息
		if (empty($_SESSION['app'])) {
			$_SESSION['app'] = (object) C('APP_INFO');
			$this->oApp = $data;
		} else {
			$this->oApp = $_SESSION['app'];
		}
		
		//加载用户数据
		//if ($this->isLogin()) {
			$this->oUser = $_SESSION['admin'];
		//} 

		//对免验证模块，不进行登录验证。
		if (in_array(ACTION_NAME,$this->aVerify)) {
			if (!$this->isLogin()) {
				$this->error('您尚未登录！', U('Login/sign_in'));
			}
		}
		if (in_array(ACTION_NAME,$this->aGroup)) {
			if (!$this->isLogin()) {
				$this->error('您尚未登录！', U('Login/sign_in'));
			}else{
				if($_SESSION['admin']['group']!=1){
				$this->error('您没有权利操作此页面！');	
				}
			}
		}
	}
	
	/*
	 * 是否已登录
	 */
	protected function isLogin() {
		return !empty($_SESSION['admin']);
	}
	

	/*
	 * ajax验证接口
	 * @param _NAME 验证单个字段是否合法，验证规则在model层$aValidate设置
	 * html用法： <input type="text" name="account" id="account" onblur="ajaxValidate(this.id)" /> <span id="_prompt_account"></span>
	 */
	public function ajaxValidate() {
		$name = getRequest('_NAME');

		die($this->model->ajaxValidate($name));
	}

	/*
	 * 检测是否post
	 */
	public function checkPost($templateFile='',$charset='',$contentType='',$content='',$prefix='') {
		if (!$this->isPost()) {
			$this->display($templateFile, $charset, $contentType, $content, $prefix);
			die;
		}
	}


	/*
	 *发送短信的接口
	 */
	public function SendMesg($con,$num){
		require_once 'HttpClient.class.php';
		$client = new HttpClient ("www.lx198.com");
		if (! $client->post ( '/sdk/send', array (
				'accName' => "1152405@qq.com",
				'accPwd' => strtoupper ( md5 ( "dd200412" ) ),
				'bizId' => date ( 'YmdHis' ),
				'content' => mb_convert_encoding ( $con, 'UTF-8', 'UTF-8' ),
				'aimcodes' =>$num ,
				'dataType'=>"xml"
		) )) {
			return false;
		} else {
			$xmlStr = $client->getContent () ;
			$doc = new DOMDocument ();
			$doc->loadXML ( $xmlStr );
			$xml = simplexml_load_string($xmlStr);
			if($xml->replyCode == 1){
				return true;
			}else{
				return false;
			}
		}
	}
 

}

?>